package com.example.teacher.Controller;

import com.example.common.constants.LengthConstants;
import com.example.common.domain.Result;
import com.example.common.domain.dto.SignInDto;
import com.example.common.domain.dto.WorkDto;
import com.example.common.utils.UUIDUtil;
import com.example.teacher.Service.AttendanceService;
import com.example.teacher.Service.HomeworkService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "老师端接口", description = "老师信息相关操作，签到，作业")
@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/teachers")
@RequiredArgsConstructor
public class MgsController {

    @Autowired
    private AttendanceService attendanceService;
    @Autowired
    private HomeworkService homeworkService;

    /**
     * 发布签到
     *
     * @param sign
     * @return
     */
    @PostMapping("/signIn")
    public Result<Object> signIn(@RequestBody SignInDto sign) {
        sign.setSignId(UUIDUtil.generate(LengthConstants.SIGN_ID_LENGTH));
        attendanceService.sendSignInNotification(sign);
        return Result.success();
    }

    /**
     * 发布作业
     *
     * @param work
     * @return
     */
    @PostMapping("/homework")
    public Result<Object> signOut(@RequestBody WorkDto work) {
        work.setHomeworkId(UUIDUtil.generate(LengthConstants.HOMEWORK_ID_LENGTH));
        System.out.println(work.getStartTime());
        System.out.println(work.getUpdateTime());
        homeworkService.sendAssignmentNotification(work);
        return Result.success();
    }


}
